import { dictionarySave } from "@/api/dataDict";

export default {
  data() {
    return {
      editForm: {
        visible: false,
        // 子组件的初始化的内容
        form: null,
        formAttrs: {
          "label-width": "80px"
        },
        title: ["编辑", "新增"],
        formType: "add",
        options: [
          {
            type: "input",
            hide: true,
            value: "",
            label: "ID",
            prop: "id",
            attrs: {
              style: {
                width: "200px"
              }
            }

          },
          {
            type: "input",
            value: "",
            label: "字典名称",
            prop: "name",
            rules: [
              {
                required: true,
                message: "字典名称不能为空",
                trigger: "blur"
              }
            ],
            attrs: {
              placeholder: "请输入字典名称",

              style: {
                width: "200px"
              },
              disabled: true
            }
          },
          {
            type: "input",
            value: "",
            label: "字典值",
            prop: "value",
            rules: [
              {
                required: true,
                message: "字典值不能为空",
                trigger: "blur"
              }
            ],
            attrs: {
              placeholder: "请输入字典值",

              style: {
                width: "200px"
              }
            }
          },
          {
            type: "input",
            value: "",
            prop: "pid",
            label: "父级ID",
            hide: true,
            attrs: {
              placeholder: "请选择父级ID",
              style: {
                width: "200px"
              }
            },
            rules: [
              {
                required: true,
                message: "父级ID不能为空",
                trigger: "blur"
              }
            ]
          },
          {
            type: "input",
            value: "",
            label: "字典备注",
            prop: "remark",
            attrs: {
              placeholder: "字典备注",

              style: {
                width: "200px"
              },
              type: "textarea"
            }
          }
        ]
      }
    };
  },
  methods: {

    async save(formData) {
      await dictionarySave(formData);
      this.$message.success("保存成功");
      this.editForm.visible = false;
      this.search();
    }

  }
};
